<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="copyright" content="www.infoearth.com" />
    <title>泉水监测</title>
    <link rel="stylesheet" href="../css/api.css">
    <link rel="stylesheet" href="../css/base.css">
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" href="../lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="../lib/jquery.mobile-1.4.5/jquery.min.js"></script>
    <script src="../lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <script type="text/javascript" src="../script/api.js"></script>
    <script src="../lib/config.js"></script>
    <script src="../lib/common.js"></script>
</head>

<body>
    <div id="wrap">
        <header id='header'>
            <nav id="nav">
                <a id="left" onclick="api.closeWin();"> <span>返回</span> </a>
                <div id="middle">
                    <strong id="title">QS01</strong>
                </div>
                <a class="rightSave" id="btnSave"><span>保存</span></a>
            </nav>
        </header>
        <div id="main">
            <div style="margin: 20px 15px;">
                <div style="float:left; margin: 20px 5px;">
                    <span>泉水量：</span>
                </div>
                <div style="float:right; margin: 0px 10px;width:90px;">
                    <label>
                        <input type="checkbox" name="chkz" id="chkJJ"> 减 </label>
                </div>
                <div style="float:right; margin: 0px 20px;width:90px;">
                    <label>
                        <input type="checkbox" name="chkz" id="chkJZ"> 增 </label>
                </div>
            </div>
            <div style="clear:both;"></div>
            <div style="margin: 0px 15px;">
                <div style="float:left; margin: 20px 5px;">
                    <span>浑浊度：</span>
                </div>
                <div style="float:right; margin: 0px 10px;width:90px;">
                    <label>
                        <input type="checkbox" name="chkz" id="chkHJ"> 减 </label>
                </div>
                <div style="float:right; margin: 0px 20px;width:90px;">
                    <label>
                        <input type="checkbox" name="chkz" id="chkHZ"> 增 </label>
                </div>
            </div>
            <div style="clear:both;"></div>
            <div style="margin: 20px 15px;">
                <div style="float:right;margin:0px 10px;">
                    <a> <img src="../image/picture_add.png" id="btnUploadImage" style="width:32px;height: 32px;"/> </a>
                </div>
                <div style="float:right;margin:0px 10px;">
                    <a> <img src="../image/camera_add.png" id="btnCamera"  style="width:32px;height: 32px;"/> </a>
                </div>
                <div style="width:80px;float:right;margin:2px 0px;">
                    <label for="name2">上传照片:</label>
                </div>
            </div>
            <div style="clear: both;"></div>
            <div id="divImages" style="margin:10px 10px;"></div>
        </div>
    </div>
</body>
<script type="text/javascript">
var pntInfo = {};
var position = null;
var pics = [];
apiready = function() {
    api.addEventListener({
        name: 'keyback'
    }, function(ret, err) {
        api.closeWin();
    });
    //获取监测点信息
    pntInfo = getCookie('monitorPointInfo');
    if (pntInfo != null && pntInfo != '') {
        pntInfo = JSON.parse(pntInfo);
        $("#title").html(pntInfo.QCQFJCD01070);
    }
    //获取设备所处位置
    api.getLocation(function(ret, err) {
        if (ret.status) {
            position = ret;
        }
    });
    $("#btnSave").click(function() {
        showSaveProgress();
        saveRecord();
        api.hideProgress();
    });
    initialCamera();
}

function getCheckHzdVal() {
    var chkJJ = $('#chkHJ').is(':checked');
    var chkJZ = $('#chkHZ').is(':checked');
    if (chkJJ == true)
        return 0;
    else if (chkJZ == true)
        return 1;
    else
        return null;
}

function getCheckJsVal() {
    var chkJJ = $('#chkJJ').is(':checked');
    var chkJZ = $('#chkJZ').is(':checked');
    if (chkJJ == true)
        return 0;
    else if (chkJZ == true)
        return 1;
    else
        return null;
}

function saveRecord() {
    Guid2(function(res) {
        var item = {
            "QCQFJSJC01010": res,
            "QCQFJSJC01020": pntInfo.QCQFJCD01010,
            "QCQFJSJC01030": getCheckJsVal(),
            "QCQFJSJC01040": getCheckHzdVal(),
            "QCQFJSJC01050": getCookie('PhoneNum'),
            "QCQFJSJC01060": getLocaleDatetime(),
            "QCQFJSJC01070": 0,
            "QCQFJSJC01080": 0,
            "QCQFJSJC01090": null,
            "QCQFJSJC01100": getCookie('QcqfMan'),
            "QCQFJSJC01110": '0'
        };
        if (pics.length > 0)
            item.QCQFJSJC01110 = '1';
        if (position != null) {
            item.QCQFJSJC01070 = position.longitude;
            item.QCQFJSJC01080 = position.latitude;
        }
        //				var data = {
        //					"record" : [item]
        //				};
        //				addRecords('qcqf', 'QCQFJSJC01', data, function(response) {
        //					saveDealwithTask(item);
        //					showMsg('保存成功！');
        //				}, showErro, false);
        $.ajax({
            url: ip_req + 'ZHFZ/ZHFZService.svc/SaveQCQFJSJC01',
            type: 'GET',
            dataType: 'jsonp',
            data: {
                parameters: JSON.stringify(item),
            }
        }).done(function(res) {
            api.hideProgress();
            saveDealwithTask(item);
            showMsg('文件信息保存成功,正在上传,请稍等...');
            //保存照片
            uploadPictures(pics, item.QCQFJSJC01010, 'qcqfApp');
        });

    });
}

//新增上报处理任务记录
function saveDealwithTask(jcInfo) {
    Guid2(function(res) {
        var hazardInfo = getCookie('hazardInfo');
        hazardInfo = JSON.parse(hazardInfo);
        var data = {
            'YJZSSBCL01010': res, //记录ID
            'YJZSSBCL01020': '手机', //来源
            'YJZSSBCL01030': jcInfo.QCQFJSJC01060, //时间
            'YJZSSBCL01040': hazardInfo.QCQFD01040 + '泉水监测', //内容
            'YJZSSBCL01050': hazardInfo.QCQFD01020, //灾害点编号
            'YJZSSBCL01060': '巡查记录', //业务类别
            'YJZSSBCL01070': jcInfo.QCQFJSJC01010, //业务数据ID
            'YJZSSBCL01080': getLocaleDatetime(), //系统时间
            'YJZSSBCL01090': null //备注
        };
        var record = {
            "record": [data]
        };
        addRecords("qcqf", "YJZSSBCL01", record, function() {}, showErro, false);
    });
}

function onPicBack(ret, err) {
    if (ret) {
        var img = "<img src='" + ret.data + "' style='width:128px;margin:10px 10px;'/>"
        $("#divImages").append(img);
        pics.push(ret.data);
    } else {
        api.alert({
            msg: err.msg
        });
    }
}

function initialCamera() {
    $("#btnUploadImage").click(function() {
        api.getPicture({
            sourceType: 'library',
            encodingType: 'jpg',
            mediaValue: 'pic',
            destinationType: 'url',
            allowEdit: false,
            quality: 50,
            targetWidth: 800,
            targetHeight: 800,
            saveToPhotoAlbum: false
        }, function(ret, err) {
            onPicBack(ret, err);
        });
    });
    $("#btnCamera").click(function() {
        api.getPicture({
            sourceType: 'camera',
            encodingType: 'jpg',
            mediaValue: 'pic'
        }, function(ret, err) {
            onPicBack(ret, err);
        });
    });
}
</script>

</html>